<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html;charset=utf-8" language="java" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <%@ include file="/assets/public.jsp"%>
    <title>文章详情</title>
    <style>
        .myList li{
            display: inline-block;
        }
    </style>
</head>
<body>
<%@include file="/assets/header.jsp"%>

<div class="d-flex align-items-stretch">
    <!-- Sidebar Navigation-->
    <%@ include file="/assets/side.jsp"%>
    <!-- Sidebar Navigation end-->
    <div class="page-content">
        <div class="page-header">
            <div class="container-fluid">
                <h2 class="h5 no-margin-bottom">文章详情</h2>
            </div>
        </div>

        <section class="no-padding-bottom">

            <div class="myTitle">
                <h3 class="text-center">${articleById.title}</h3>
                <c:if test="${b}">
                    <input id="sub" type="button" value="取消收藏" class="btn btn-info">
                </c:if>
                <c:if test="${!b}">
                    <input id="sub" type="button" value="收藏文章" class="btn btn-info">
                </c:if>
            </div>

            <div class="myContent">
                <p class="h6"><strong>发布人：</strong>${articleById.publish_real_name}</p>
                <p class="h6"><strong>创建时间：</strong>${articleById.publish_date}</p>
                <p class="h6"><strong>浏览次数：</strong>${articleById.browse_count}</p>
                <p class="h6"><strong>收藏次数：</strong>${articleById.count}</p>
                <textarea style="padding: 2px" disabled="disabled" class="form-control" rows="11">${articleById.content}</textarea>
                <input id="path" value="${pageContext.request.contextPath}" type="hidden" />
                <input id="artId" value="${articleById.id}" type="hidden" />
            </div>

            <div class="myList">
                <p>您关注的小伙伴等人也收藏了该文章</p>
                <ul>
                    <c:forEach items="${focusFavoriteById}" var="focus">
                        <li class="list-group-item">
                            <c:if test="${focus.realName == null}">
                                <a href="#">${focus.username}</a>
                            </c:if>
                            <c:if test="${focus.realName != null}">
                                <a href="#">${focus.realName}</a>
                            </c:if>
                        </li>
                    </c:forEach>
                </ul>
            </div>
        </section>
        <%@include file="/assets/footer.jsp"%>
    </div>
</div>
</body>
<script>
    $("#sub").click(function () {
        var value = $("#sub").val();
        var path = $("#path").val();
        var artId = $("#artId").val();
        if (value === "取消收藏") {
            $("#sub").val("收藏文章");
        }else {
            $("#sub").val("取消收藏");
        }
        $.ajax({
            url: path + '/article/updateCollect?artId=' + artId,
            type:'post',
            data:{
                collect:value
            },
            success:function (data) {
                if (data === "0"){
                    layer.msg("收藏成功");
                }
                else {
                    layer.msg("取消收藏");
                }
            }
        })
    })
</script>
</html>